﻿@namespace Masa.Blazor.Presets
@using Masa.Blazor.Presets.PageStack
@inherits PatternPathComponentBase
@inject IJSRuntime JSRuntime

<PPageContainer Style="@GetStyle()"
                Class="@GetClass()"
                IncludePatterns="@TabbedPatterns"
                SelfPatterns="@SelfPatterns"
                Strict>
    @ChildContent
</PPageContainer>

<CascadingValue Value="this" IsFixed>
    @for (var i = 0; i < Pages.Count; i++)
    {
        var index = i;
        var path = Pages.ElementAt(index);
        var isTop = i == Pages.Count - 1;
        var canRender = isTop && NavigationManager.GetAbsolutePath().Equals(path.AbsolutePath, StringComparison.OrdinalIgnoreCase);

        <PPageStackItem Active="@path.Stacked"
                        CanRender="@canRender"
                        OnGoBack="@HandleOnPrevious"
                        SelectorCaptureAction="u => path.Selector = u"
                        Index="index"
                        @key="@path.Id">
            @ChildContent
        </PPageStackItem>
    }
</CascadingValue>